// http://poj.org/problem?id=3253

#include <iostream>
#include <vector>
#include <queue>
using namespace std;

int main() {
    int n, t;
    scanf("%d", &n);
    priority_queue<int, vector<int>, greater<int> > Q;
    for (int i = 0; i < n; i++) {
        scanf("%d", &t);
        Q.push(t);
    }

    long long ans = 0;
    while (Q.size() > 1) {
        const int t1 = Q.top();     Q.pop();
        const int t2 = Q.top();     Q.pop();
        long s = t1 + t2;
        ans += s;
        Q.push(s);
    }

    printf("%lld\n", ans);
    return 0;
}